package cc.mrbird.common.domin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel("返回类")
public class Message<T> {
	@ApiModelProperty("状态码")
	private Integer code;
	@ApiModelProperty("结果集")
	private T data;
	@ApiModelProperty("返回信息")
	private String msg;

	private PageUtil page;

	// 成功
	private static final Integer SUCCESS = 0;
	// 警告
	private static final Integer WARN = 1;
	// 异常 失败
	private static final Integer FAIL = 500;

	public static <T>Message<T> error(){
		return new Message<T>(FAIL,"操作失败，请联系网站管理员",null);
	}

	public static <T>Message<T> error(String msg){
		return new Message<T>(FAIL,msg,null);
	}

	public static <T>Message<T> warn(){
		return new Message<T>(WARN,"操作失败，请联系网站管理员",null);
	}

	public static <T>Message<T> ok(T data){
		return new Message<T>(SUCCESS,"操作成功",data);
	}

	public static <T>Message<T> ok(){
		return new Message<T>(SUCCESS,"操作成功",null);
	}

	public static <T>Message<T> ok(int count) {
		return count>=0?ok():warn();
	}

	public static <T>Message<T> ok(boolean boo) {
		return boo?ok():warn();
	}

	public static <T>Message<T> ok(IPage t) {
		return new Message(SUCCESS,"操作成功",t.getRecords(),new PageUtil(t));
	}

/*
	public static <T>Message<T> ok(PageInfo t) {
		return new Message(SUCCESS,"操作成功",t.getList(),new PageUtil(t));
	}
*/

	public Message() {
	}

	public Message(Integer code,String msg, T data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public Message(Integer code,String msg, T data , PageUtil page) {
		this.code = code;
		this.msg = msg;
		this.data = data;
		this.page = page;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public PageUtil getPage() {
		return page;
	}

	public void setPage(PageUtil page) {
		this.page = page;
	}
}
